/*
 * Copyright 2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.pajamas.example.client.web.controller;

import org.pajamas.example.client.web.vo.TestMusicReqVo;
import org.pajamas.starter.core.vo.PajamasValidStrategy;
import org.pajamas.starter.core.vo.ResultVo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.ExternalDocumentation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * @author william
 * @since 2024/1/14
 */
@Tag(
        name = "test validation api",
        description = "as a example for pajamas.starter.web.validation",
        externalDocs = @ExternalDocumentation(
                description = "this is the api detail",
                url = "http://localhost:8080/swagger-ui/index.html"
        )
)
@RestController
@RequestMapping("/test-validation")
public class TestValidationController {
    @Operation(
            summary = "a simple test api",
            description = "just return your type-in directly",
            parameters = {
                    @Parameter(
                            name = "arg",
                            description = "your input",
                            required = true,
                            example = "this is a demo"
                    )
            },
            responses = {
                    @ApiResponse(
                            responseCode = "200",
                            description = "response success",
                            content = @Content(
                                    mediaType = "application/json",
                                    schema = @Schema(
                                            title = "ResultVo",
                                            description = "a unified response body entity",
                                            anyOf = {ResultVo.class}
                                    )
                            )
                    )
            }
    )
    @RequestMapping("/simple")
    public ResultVo aSimpleRequest(@RequestParam String arg) {
        return ResultVo.builder().payload(arg).build();
    }

    @RequestMapping("/normal")
    public ResultVo normal(@PajamasValidStrategy @RequestBody TestMusicReqVo reqVo) {
        return ResultVo.builder().payload(reqVo).build();
    }
}
